#ifndef __port__
#define __port__
class port: public object {
    FILE *fp;
    bool isronly;

public:
    port(FILE *f, bool is = true): object(""), fp(f), isronly(is) { }
    std::string read() {
	std::string str;
	int c;
	if (!isronly)
	    throw Error(new error(error::wonly));
	if (isatty(fileno(fp)))
	    fprintf(stderr, "> ");
	while ((c = getc(fp)) != EOF && c != '\n')
	    str += c;
	return str; 
    }
    void write(std::string str) {
	if (isronly)
	    throw Error(new error(error::ronly));
	fprintf(fp, "%s", str.c_str());
    }
    std::string get_type() { return "#<Port>"; }
};
typedef boost::shared_ptr<port> Port;
#endif
